import { productApi } from "@/api/erp/drug/drug";
import { SaleOrderApi } from "@/api/erp/sale/order";
import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicColumn, BasicTable, FormSchema, useRender, useTable } from "@/components/Table";
import { useTranslation } from "react-i18next";
const newAdd = (props: any) => {
	const en_vi = "drugStorage.purchasingManagement.purchaseOrder";
	const { t } = useTranslation();
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		console.log("data>>>>>>>>>>>>>>>", data);
	});
	const schemas: FormSchema[] = [
		{
			label: t(`drugStorage.salesManagement.saleOrder.orderId`),
			field: "orderId",
			component: "Input"
		},
		{
			label: t("drugStorage.productName"),
			component: "ApiSelect",
			field: "productId",
			componentProps: {
				api: productApi.getproductSimpleList,
				labelField: "productName",
				valueField: "productId",
				immediate: false,
				params: {
					bizType: "2"
				}
			}
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t(`drugStorage.salesManagement.saleOrder.orderId`),
			dataIndex: "orderId"
		},
		{
			title: t(`drugStorage.inventoryManagement.otherOutboundItems.customerName`),
			dataIndex: "customerName"
		},
		{
			title: t("drugStorage.productName"),
			dataIndex: "productNames"
		},
		{
			title: t(`${en_vi}.orderTime`),
			dataIndex: "orderTime",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`drugStorage.inventoryManagement.inventoryDetails.createdBy`),
			dataIndex: "createdByName"
		},
		{
			title: t(`drugStorage.inventoryManagement.inventoryDetails.totalCount`),
			dataIndex: "totalCount"
		},
		{
			title: t(`drugStorage.inventoryManagement.otherInboundItems.totalPrice`),
			dataIndex: "totalPrice"
		},
		{
			title: t(`drugStorage.purchasingManagement.purchaseOrder.totalTaxPrice`),
			dataIndex: "totalTaxPrice"
		}
	];
	const [registerTable, { getSelectRows }] = useTable({
		api: SaleOrderApi.getSaleOrderPage,
		columns,
		rowSelection: true,
		formConfig: {
			labelWidth: 150,
			schemas,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 12 },
			actionColOptions: { span: 24 }
		},
		bordered: true,
		useSearchForm: true,
		searchInfo: {
			bizType: "2",
			returnEnable: true
		}
	});
	const handleSubmit = async () => {
		const orderItem = getSelectRows();
		props.setOrderItem(orderItem[0]);
		closeDrawer();
	};
	return (
		<BasicDrawer
			size="large"
			{...props}
			title={t("drugStorage.selectPurchaseOrder")}
			register={registerDrawer}
			ok={handleSubmit}
			showFooter={true}
		>
			<BasicTable register={registerTable}></BasicTable>
		</BasicDrawer>
	);
};
export default newAdd;
